package proyecto1;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class IngresoDemandante extends javax.swing.JDialog {

    static String nombre, rut, carnet, numeTelefono = null;
    Demandantes demandantes = null;

    public IngresoDemandante(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        addItemalBox();
        this.setLocationRelativeTo(null);
        /// si ingreso un dato en una casilla vacia marcara error
        this.ErrorNombre.setVisible(false);
        this.ErrorRut.setVisible(false);
        this.ErrorDireccion.setVisible(false);
        this.ErrorTelefono.setVisible(false);
        this.ErrorClaseCarnet.setVisible(false);
        this.ErrorNTitulaciones.setVisible(false);
        this.ErrorEspecialidad.setVisible(false);
        this.ErrorUniversidad.setVisible(false);
        //Error de tipeos
        this.jL_ErroTipeoNombre.setVisible(false);
        this.jL_ErroTipeoRut.setVisible(false);
        this.jL_ErroTipeoCarnet.setVisible(false);
        this.jL_ErrorTipeoTelefono.setVisible(false);

    }

    public void addItemalBox() {  // para agregar las carreras

        for (int i = 0; i < Main.profesiones.length; i++) {
            trabajos.addItem(Main.profesiones[i]);
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        textoNombre = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        textoRut = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        botonGuardar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        trabajos = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        TextoDireccion = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        TextoTelefono = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        TextoCarnet = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        TextoTitulacion = new javax.swing.JTextField();
        LabelEsp = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextoEspecialidad = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        TextoUniversidad = new javax.swing.JTextField();
        ErrorNombre = new javax.swing.JLabel();
        Volver = new javax.swing.JButton();
        ErrorRut = new javax.swing.JLabel();
        ErrorDireccion = new javax.swing.JLabel();
        ErrorTelefono = new javax.swing.JLabel();
        ErrorClaseCarnet = new javax.swing.JLabel();
        ErrorNTitulaciones = new javax.swing.JLabel();
        ErrorEspecialidad = new javax.swing.JLabel();
        ErrorUniversidad = new javax.swing.JLabel();
        jL_ErroTipeoNombre = new javax.swing.JLabel();
        jL_ErroTipeoRut = new javax.swing.JLabel();
        jL_ErroTipeoCarnet = new javax.swing.JLabel();
        jL_ErrorTipeoTelefono = new javax.swing.JLabel();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        textoNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textoNombreActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre: ");

        textoRut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textoRutActionPerformed(evt);
            }
        });

        jLabel2.setText("Rut: ");

        botonGuardar.setText("Guardar Cambios");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonCancelar.setText("Borrar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        jLabel3.setText("Profesión: ");

        trabajos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trabajosActionPerformed(evt);
            }
        });

        jLabel4.setText("Direccion");

        TextoDireccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TextoDireccionActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        jLabel5.setText("Formulario Demandante");

        jLabel6.setText("Telefóno");

        jLabel7.setText("Clase carnet");

        jLabel8.setFont(new java.awt.Font("Lucida Grande", 1, 18)); // NOI18N
        jLabel8.setText("Curriculum: ");

        jLabel9.setText("Numero de titulaciones");

        LabelEsp.setText("Titulaciones y especialidad: ");

        TextoEspecialidad.setColumns(20);
        TextoEspecialidad.setRows(5);
        jScrollPane1.setViewportView(TextoEspecialidad);

        jLabel11.setText("Universidad donde se titulo");

        ErrorNombre.setForeground(new java.awt.Color(255, 0, 0));
        ErrorNombre.setText("* Campo obligatorio");

        Volver.setText("Volver al menú");
        Volver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                VolverActionPerformed(evt);
            }
        });

        ErrorRut.setForeground(new java.awt.Color(255, 0, 0));
        ErrorRut.setText("* Campo obligatorio");

        ErrorDireccion.setForeground(new java.awt.Color(255, 0, 0));
        ErrorDireccion.setText("* Campo obligatorio");

        ErrorTelefono.setForeground(new java.awt.Color(255, 0, 0));
        ErrorTelefono.setText("* Campo Obligatorio");

        ErrorClaseCarnet.setForeground(new java.awt.Color(255, 0, 0));
        ErrorClaseCarnet.setText("* Campo obligatorio");

        ErrorNTitulaciones.setForeground(new java.awt.Color(255, 0, 0));
        ErrorNTitulaciones.setText("* Campo obligatorio");

        ErrorEspecialidad.setForeground(new java.awt.Color(255, 0, 0));
        ErrorEspecialidad.setText("* Campo obligatorio");

        ErrorUniversidad.setForeground(new java.awt.Color(255, 0, 0));
        ErrorUniversidad.setText("* Campo obligatorio");

        jL_ErroTipeoNombre.setForeground(new java.awt.Color(255, 0, 0));
        jL_ErroTipeoNombre.setText("Debe ingresar un nombre verdaddero!");

        jL_ErroTipeoRut.setForeground(new java.awt.Color(255, 0, 0));
        jL_ErroTipeoRut.setText("Rut inválido!");

        jL_ErroTipeoCarnet.setForeground(new java.awt.Color(255, 0, 0));
        jL_ErroTipeoCarnet.setText("Carnet Inválido!");

        jL_ErrorTipeoTelefono.setForeground(new java.awt.Color(255, 0, 0));
        jL_ErrorTipeoTelefono.setText("Telefono inválido!");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel2)
                            .add(jLabel1)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .add(8, 8, 8)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(trabajos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 164, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(layout.createSequentialGroup()
                                .add(24, 24, 24)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, TextoDireccion)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, TextoTelefono, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, TextoCarnet))
                                .add(18, 18, 18)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .add(ErrorTelefono)
                                        .add(18, 18, 18)
                                        .add(jL_ErrorTipeoTelefono))
                                    .add(ErrorDireccion)
                                    .add(layout.createSequentialGroup()
                                        .add(ErrorClaseCarnet)
                                        .add(18, 18, 18)
                                        .add(jL_ErroTipeoCarnet))))
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                .add(Volver)
                                .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 439, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(18, 18, 18)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, textoNombre)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, textoRut, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE))
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createSequentialGroup()
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(ErrorNombre))
                                    .add(layout.createSequentialGroup()
                                        .add(18, 18, 18)
                                        .add(ErrorRut)))
                                .add(23, 23, 23)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jL_ErroTipeoRut)
                                    .add(jL_ErroTipeoNombre)))))
                    .add(layout.createSequentialGroup()
                        .add(botonGuardar)
                        .add(76, 76, 76)
                        .add(botonCancelar))
                    .add(jLabel4)
                    .add(jLabel7)
                    .add(jLabel8)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel9)
                            .add(LabelEsp)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel11))
                        .add(23, 23, 23)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(ErrorEspecialidad))
                            .add(layout.createSequentialGroup()
                                .add(TextoUniversidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(ErrorUniversidad))
                            .add(layout.createSequentialGroup()
                                .add(TextoTitulacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(27, 27, 27)
                                .add(ErrorNTitulaciones)))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(jLabel5)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(textoNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1)
                    .add(ErrorNombre)
                    .add(jL_ErroTipeoNombre))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(textoRut, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(ErrorRut)
                    .add(jL_ErroTipeoRut))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(trabajos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(TextoDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ErrorDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(TextoTelefono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ErrorTelefono)
                    .add(jL_ErrorTipeoTelefono))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(TextoCarnet, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ErrorClaseCarnet)
                    .add(jL_ErroTipeoCarnet))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel8)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel9)
                    .add(TextoTitulacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ErrorNTitulaciones))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(LabelEsp)
                    .add(ErrorEspecialidad))
                .add(35, 35, 35)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(TextoUniversidad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ErrorUniversidad))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 104, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(botonGuardar)
                    .add(botonCancelar)
                    .add(Volver))
                .add(30, 30, 30))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void textoRutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textoRutActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_textoRutActionPerformed

    static boolean validarNombre(String nombre) {
        char cnombre[] = new char[nombre.length()];
        for (int i = 0; i < nombre.length(); i++) {
            cnombre[i] = nombre.charAt(i);
        }
        boolean validar = true;
        for (int i = 0; i < nombre.length(); i++) {
            // usando el codigo ascii para las mayusculas y las minusculas
            if ((cnombre[i] >= 65 && cnombre[i] <= 90) || (cnombre[i] >= 97 && cnombre[i] <= 122)) {
                continue; // continua con el siguiente char.
            } else {
                validar = false;
                break; // encontro un error.
            }
        }
        return validar;
    }

    static boolean validarRut(String rut) {
        int largo = 0, digito, sumarut = 0, multiplorut = 2, digitousuario = 0;
        boolean validarguion = false, validarpunto = false;

        char crut[] = new char[rut.length()];
        for (int i = 0; i < rut.length(); i++) {
            crut[i] = rut.charAt(i);
            if (crut[i] == '.') {
                validarpunto = true;
            }
            if (crut[i] == '-') {
                validarguion = true;
            }
        }
        if (!validarguion || crut[rut.length() - 1] == '-' || crut[rut.length() - 2] != '-' || validarpunto == true) {
            //System.out.println("Rut Invalido.");
            return false;
        }
        for (int i = 0; i < rut.length(); i++) {
            if (crut[i] == '-') {
                if (crut[i + 1] == 'k' || crut[i + 1] == 'K') {
                    digitousuario = 10;
                } else if ((crut[i + 1] - 48) == 0) {
                    digitousuario = 11;
                } else {
                    digitousuario = (crut[i + 1] - 48);
                }
                largo = i;
                break;
            }
        }
        for (int i = largo - 1; i >= 0; i--) {
            sumarut += (multiplorut * (crut[i] - 48));
            multiplorut++;
            if (multiplorut == 8) {
                multiplorut = 2;
            }
        }
        digito = sumarut % 11;
        digito = 11 - digito;
        if (digito == digitousuario) {
            //System.out.println("Rut Valido.");

            return true;
        } else {
            //System.out.println("Rut Invalido");

            return false;
        }
    }

    static boolean validarCarnet(String carnet) {
        boolean validar = true;
        if (carnet == "A" || carnet == "B" || carnet == "C" || carnet == "a" || carnet == "b" || carnet == "c") {
            System.out.println("carnet válido");
            return validar = true;


        } else {
            System.out.println("carnet inválido");
            return validar = false;
        }

    }

    public boolean comprobarCampos() { // para comprobar si la casilla esta vacia
        boolean validar = false;
        if (textoNombre.getText().equals("")) {
            this.ErrorNombre.setVisible(true);
            validar = true;
        }
        if (textoRut.getText().equals("")) {
            this.ErrorRut.setVisible(true);
            validar = true;
        }
        if (TextoDireccion.getText().equals("")) {
            this.ErrorDireccion.setVisible(true);
            validar = true;
        }
        if (TextoTelefono.getText().equals("")) {
            this.ErrorTelefono.setVisible(true);
            validar = true;
        }
        if (TextoCarnet.getText().equals("")) {
            this.ErrorClaseCarnet.setVisible(true);
            validar = true;
        }
        if (TextoTitulacion.getText().equals("")) {
            this.ErrorNTitulaciones.setVisible(true);
            validar = true;
        }
        if (TextoEspecialidad.getText().equals("")) {
            this.ErrorEspecialidad.setVisible(true);
            validar = true;
        }
        if (TextoUniversidad.getText().equals("")) {
            this.ErrorUniversidad.setVisible(true);
            validar = true;
        }

        return validar;
    }

    public void guardarArchivo() throws FileNotFoundException, IOException {

        FileWriter fw = new FileWriter("demandantes.txt");
        BufferedWriter bw = new BufferedWriter(fw);

        bw.write(demandantes.getNombre()+"\n");
        bw.write(demandantes.getClaseCarnetm()+"\n");
        bw.write(demandantes.getDireccion()+"\n");
        bw.write(demandantes.getEspecialidad()+"\n");
        bw.write(demandantes.getNumeroT()+"\n");
        bw.write(demandantes.getProfesion()+"\n");
        bw.write(demandantes.getRut()+"\n");
        bw.write(demandantes.getTelefono()+"\n");
        bw.write(demandantes.getUniversidad()+"\n");
        
        bw.close();
        fw.close();

        //lectura
        FileReader fr = new FileReader("demandantes.txt");
        BufferedReader bf = new BufferedReader(fr);
        String cadena;
        while ((cadena = bf.readLine()) != null) {
            System.out.println(demandantes.getNombre());
        }
        bf.close();
        fr.close();
    }

private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
// cuando presiona el boton cancelar para que quede el espacio vacio
    textoNombre.setText("");
    textoRut.setText("");
    this.TextoDireccion.setText("");
    this.TextoCarnet.setText("");
    this.TextoUniversidad.setText("");
    this.TextoEspecialidad.setText("");
    this.TextoTitulacion.setText("");
    this.TextoTelefono.setText("");

// campo vacio
    this.ErrorNombre.setVisible(false);
    this.ErrorRut.setVisible(false);
    this.ErrorDireccion.setVisible(false);
    this.ErrorTelefono.setVisible(false);
    this.ErrorClaseCarnet.setVisible(false);
    this.ErrorNTitulaciones.setVisible(false);
    this.ErrorEspecialidad.setVisible(false);
    this.ErrorUniversidad.setVisible(false);
// tipeo
    this.jL_ErroTipeoNombre.setVisible(false);
    this.jL_ErroTipeoRut.setVisible(false);
    this.jL_ErroTipeoCarnet.setVisible(false);
    this.jL_ErrorTipeoTelefono.setVisible(false);

}//GEN-LAST:event_botonCancelarActionPerformed

private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed

    nombre = this.textoNombre.getText();
    rut = this.textoRut.getText();
    numeTelefono = this.TextoTelefono.getText();
    carnet = this.TextoCarnet.getText();
    /*
     * if (validarNombre(nombre)) { // el nombre es correcto
     * //System.out.println("Nombre correcto"); } else {
     * this.jL_ErroTipeoNombre.setVisible(true); // nombre incorrecto return; //
     * termina la funcion } if(validarRut(rut)==false){
     * this.jL_ErroTipeoRut.setVisible(true); return ; }else{
     * this.jL_ErroTipeoRut.setVisible(false); }
     * if(validarCarnet(carnet)==false){
     * this.jL_ErroTipeoCarnet.setVisible(true); }
     */
    if (comprobarCampos()) {
        return;
    }
    // es para que no de un error al ingresar una letra y solo muestre un mensaje que hay que ingresar un numero
     /*
     * try { numeTelefono = Integer.parseInt(this.TextoTelefono.getText()); }
     * catch (Exception e) { this.jL_ErrorTipeoTelefono.setVisible(true); }
     *
     *
     * if (numeTelefono < 9999999 || numeTelefono > 1000000) {
     * this.jL_ErrorTipeoTelefono.setVisible(true); return; }
     */

    demandantes = new Demandantes();
    demandantes.setNombre(textoNombre.getText()); // retorna lo que hay en el cuadro blanco 
    demandantes.setRut(textoRut.getText());
    demandantes.setTelefono(TextoTelefono.getText());
    demandantes.setDireccion(TextoDireccion.getText());
    demandantes.setClaseCarnetm(TextoCarnet.getText());
    demandantes.setEspecialidad(TextoEspecialidad.getText());
    demandantes.setUniversidad(TextoUniversidad.getText());
    demandantes.setNumeroT(TextoTitulacion.getText());

    String profe = (String) trabajos.getSelectedItem();
    demandantes.setProfesion(profe);




    Main.datosDem.add(demandantes);
    
    try {
        guardarArchivo();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(IngresoDemandante.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(IngresoDemandante.class.getName()).log(Level.SEVERE, null, ex);
    }
    this.setVisible(false); // para esconder (la ventana
    Main.contador++;
}//GEN-LAST:event_botonGuardarActionPerformed

private void trabajosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trabajosActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_trabajosActionPerformed

private void TextoDireccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextoDireccionActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_TextoDireccionActionPerformed

private void textoNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textoNombreActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_textoNombreActionPerformed

private void VolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VolverActionPerformed
    this.setVisible(false);
}//GEN-LAST:event_VolverActionPerformed

    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(IngresoDemandante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(IngresoDemandante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(IngresoDemandante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(IngresoDemandante.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ErrorClaseCarnet;
    private javax.swing.JLabel ErrorDireccion;
    private javax.swing.JLabel ErrorEspecialidad;
    private javax.swing.JLabel ErrorNTitulaciones;
    private javax.swing.JLabel ErrorNombre;
    private javax.swing.JLabel ErrorRut;
    private javax.swing.JLabel ErrorTelefono;
    private javax.swing.JLabel ErrorUniversidad;
    private javax.swing.JLabel LabelEsp;
    private javax.swing.JTextField TextoCarnet;
    private javax.swing.JTextField TextoDireccion;
    private javax.swing.JTextArea TextoEspecialidad;
    private javax.swing.JTextField TextoTelefono;
    private javax.swing.JTextField TextoTitulacion;
    private javax.swing.JTextField TextoUniversidad;
    private javax.swing.JButton Volver;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jL_ErroTipeoCarnet;
    private javax.swing.JLabel jL_ErroTipeoNombre;
    private javax.swing.JLabel jL_ErroTipeoRut;
    private javax.swing.JLabel jL_ErrorTipeoTelefono;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField textoNombre;
    private javax.swing.JTextField textoRut;
    private javax.swing.JComboBox trabajos;
    // End of variables declaration//GEN-END:variables
}
